<template>
  <div>
    <router-link tsg="div" to="/" class="abs" v-show="showAbs">
      <span class="iconfont abs-back-icon">&#xe624;</span>
    </router-link>
    <div class="fixed" v-show="!showAbs" :style="opacityStyle">
      景点详情
      <router-link to="/">
        <span class="iconfont header-back">&#xe624;</span>
      </router-link>
    </div>
  </div>
</template>
<script>
export default {
  name: 'DetailHeader',
  data: function () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll: function () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>
<style lang="stylus" scoped>
@import "~styles/varible.styl"
  .abs
    position: absolute
    left: .2rem
    top: .2rem
    width: .6rem
    height:.6rem
    line-height: .6rem
    border-radius: 50%
    background: rgba(0, 0, 0, 0.8)
    text-align center
    .abs-back-icon
      color: #ffffff
  .fixed
    z-index: 2
    position: fixed
    top: 0
    left: 0
    right: 0
    height: .86rem
    line-height: .86rem
    text-align: center
    background: $bgColor
    color: #ffffff
    font-size: .32rem
    .header-back
      position: absolute
      left: .2rem
      top: 0
      color: #fff
</style>
